/*
 *  Application Suit Framework
 *  all copyrights reserved by LaserBin.
 *
 *  [file] : ASControl.h
 *  [description] : basic control
 */

#ifndef __AS_CONTROLS__H__
#define __AS_CONTROLS__H__

#include "..\base\ASDataType.h"
#include "..\base\ASStdLib.h"
#include "..\base\ASGraphic.h"
#include "..\base\ASUtil.h"
#include "..\tool\ASLog.h"
struct _as_control;
typedef struct _as_control as_control;

typedef as_ret (*control_keyevt_hdlr)(as_control* ctrl_p, ASINT event, ASINT keycode);
typedef ASVOID (*control_change_area_hdlr)(as_control* ctrl_p, as_rect area);


typedef enum
{
    AS_CTRL_IMAGE,
    AS_CTRL_LABEL,
    AS_CTRL_SCROLLTEXT,
    AS_CTRL_PROGRESSBAR,
    AS_CTRL_BUTTON,
    AS_CTRL_RANKING,
    AS_CTRL_WAITING,
    AS_CTRL_POPUP,
    AS_CTRL_HYPERLINK,
    AS_CTRL_TABLEBAR,
    AS_CTRL_LISTITEM,
    AS_CTRL_LIST,
    AS_CTRL_FILLEDAREA,
    AS_CTRL_ADVBAR,//advbar
    AS_CTRL_TEXTVIEW,
    AS_CTRL_SCROLLBAR,

    AS_CTRL_MAX
} as_control_type;

struct _as_control
{
    /*attributes*/
    as_control_type ctrl_type;
    as_rect area;/*depend on screen area*/
    ASINT show_hdlr;
    ASINT if_hidden;

    /*methods*/
    /*
     *	[description] paint a control
     *  [param] ctrl_p : which you want to paint
     *  this function is virtual,each control will implement it
     */
    ASVOID (*paint_hdlr)(as_control* ctrl_p);

    /*
     *	[description] a control deal the pen event
     *  [param] ctrl_p : which one to deal pen
     *  [param] event : event of pen (VM_PEN_EVENT_TAP,VM_PEN_EVENT_MOVE,VM_PEN_EVENT_RELEASE,
                                      VM_PEN_EVENT_LONG_TAP,VM_PEN_EVENT_DOUBLE_CLICK,VM_PEN_EVENT_REPEAT)
     *  [param] x : where the event happened
     *  [param] y : where the event happened
     *  [return] as_ret : AS_OK means it deals this event; AS_IGNORE means it don't care; otherwise are error code
     *  this function is virtual,each control will implement it
     */
    as_ret (*pen_hdlr)(as_control* ctrl_p, ASINT event, ASINT x, ASINT y);

    /*
     *	[description] a control deal the key event
     *  [param] ctrl_p : which control want to deal key event
     *  [param] event : event of key (VM_KEY_EVENT_UP,VM_KEY_EVENT_DOWN,VM_KEY_EVENT_LONG_PRESS,VM_KEY_EVENT_REPEAT)
     *  [param] keycode : which key generated the event (VM_KEY_UP ~ VM_KEY_STAR and other key code in vmio.h)
     *  [return] as_ret : AS_OK means it deals this event; AS_IGNORE means it don't care; otherwise are error code
     *  this function is virtual,each control will implement it
     */
    as_ret (*key_hdlr)(as_control* ctrl_p, ASINT event, ASINT keycode);

    /*
     *	[description] change the area of ctrl_p
     *  [param] ctrl_p : which you want to change property
     *  [param] area : target area
     *  [return] as_ret : AS_OK ,or error code
     */
    ASVOID (*change_area_hdlr)(as_control* ctrl_p, as_rect area);

    /*
     *	[description] move the position of this control
     *  [param] ctrl_p : which control you want to move
     *  [param] x_off : offset relative to area.x
     *  [param] y_off : offset relative to area.y
     */
    ASVOID (*move)(as_control* ctrl_p, ASINT x_off, ASINT y_off);

    ASVOID (*set_hidden)(as_control* ctrl_p, ASINT if_hidden);

    ASINT (*get_hidden)(as_control* ctrl_p);

    ASVOID (*set_show_hdlr)(as_control* ctrl_p, ASINT hdlr);

    ASINT (*get_show_hdlr)(as_control* ctrl_p);
};

/*
 *	[description] create an exactly control through this function
 *  [param] type : config which type of control you want to create (enum as_control_type)
 *  [param] paint_buf : which display buffer do you want to paint this control on
 *  [param] area : the area of this control
 *  [param] extra_param_cnts : counts of extra parameters
 *  [param] extra_param_p : array pointer of extra parameters
 *  [return] as_control* : if success,return pointer of created control,else return NULL
 */
as_control* as_ctrl_create(as_control_type type, as_rect area,
                           ASINT extra_param_cnts, ASVOID** extra_param_p);

/*
 *	[description] destroy an exactly control through this function
 *  [param] ctrl_p : which control you want to destroy
 *  [return] as_ret : AS_OK or error codes
 */
as_ret as_ctrl_destroy(as_control* ctrl_p);

/*just for all detail controls init action*/
ASVOID as_ctrl_init(as_control* ctrl_p, as_rect area);

/* just for control flush immediately */
ASVOID as_ctrl_flush(ASVOID);

#endif//__AS_CONTROLS__H__